
local UserBaseInfo = require("app.public.dao.UserBaseInfo")

local EliteMatchChampionRender = app.mvc.createRenderClass(...)

function EliteMatchChampionRender.create(node)
    local sprite = EliteMatchChampionRender.extend(node)
    sprite:init()
    return sprite
end

function EliteMatchChampionRender:init(data)
    self.super.init(self, data)
    self:setContentSize(self._ui.Panel:getContentSize())
    
    self._tltText = self._ui["Panel/tlt"] -- 玩法名称
    self._seasonText = self._ui["Panel/text_mode"] -- 赛季
    self._dateText = self._ui["Panel/text_date"] -- 赛季时间
    self._nameText = self._ui["Panel/Panel_first/name"] -- 玩家名字
    self._serverText = self._ui["Panel/Panel_first/server"] -- 区服

    local info = UD.csEliteMatch:getPlayInfoById(UD.csEliteMatch:getOpenPlayId())
    if info and info.conf then
        self._tltText:setString(L(info.conf.name))
    end
    self._seasonText:setString(string.format(L("EliteMatchTip1"), info.id))
    local openTimeStr = os.date("%m.%d", info.startTime)
    local endTimeStr = os.date("%m.%d", info.endTime)
    self._dateText:setString(openTimeStr.."-"..endTimeStr)
    self._ui.Panel_first:setVisible(false)
    
    self._ui.btn_rank:addClickEventListener(function()
        -- 超级排行榜
        local param = (info.playId == Enums.TeamTarget.eliteMatchArena) and Enums.SuperRankMenu.CSArena or Enums.SuperRankMenu.CSDuel
        UIHandler:handleMessage({id = Constant.FUNC_TYPE_SUPER_RANK,mode = "open", menuType = param})
    end)
end

function EliteMatchChampionRender:refresh()
    if self._data then
        local data = self._data        
        self.champion = data.championInfo and UserBaseInfo.new(data.championInfo)
        self._ui.Node_1:removeAllChildren()
        if self.champion then
            local AvatarFactory = app:getClass("AvatarFactory")
            local character = AvatarFactory.createHeroIgnoreMount(self.champion)
            character:playAni({name = "mapidle"})
            self._ui.Node_1:addChild(character)
            self._nameText:setString(self.champion.name)
            self._serverText:setString(app.channelAPI:getServerNameByIndex(data.serverID))
            self._ui.Panel_first:setVisible(true)
        end
    end
end

return EliteMatchChampionRender